﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace THEMXOASUA
{
    class HOADONDAL
    {

        public HOADONDAL()
        {
        }
       
        public DataTable DOCDANHSACHHoaDon()
        {
            SqlConnection conn = SQLDATABASE.Connection;
            conn.Open();
            SqlCommand cmd = new SqlCommand("SELECT * FROM HOADON inner join hanghoa on HOADON.mahang=HANGHOA.mahang", conn);
            SqlDataReader dr = cmd.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);
            return dt;

        }
        public void XOAHOADON(string sohd)
        {
            SqlConnection conn = SQLDATABASE.Connection;
            conn.Open();
            SqlCommand cmd = new SqlCommand("DELETE FROM HOADON  WHERE sohd='" + sohd + "'", conn);
            cmd.ExecuteNonQuery();
            conn.Close();
        }

        public void SUAHOADON(string shd,string sohd, string mahang, double soluong, double dongia, string diengiai)
        {
            SqlConnection conn = SQLDATABASE.Connection; 
            conn.Open();
 SqlCommand cmd = new SqlCommand("update  HOADON  set sohd='" + sohd + "', mahang='" + mahang +"', soluong='" + soluong.ToString() + "', dongia='" + dongia.ToString() + "',  diengiai='" + diengiai + "' where sohd='" + shd + "'", conn);
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        public void THEMHOADON(string sohd, string mahang, double soluong, double dongia, double trigia, double khuyenmai, string diengiai)

        {
            SqlConnection conn = SQLDATABASE.Connection;
            conn.Open();
            SqlCommand cmd = new SqlCommand("SELECT * FROM HOADON inner join hanghoa on HOADON.mahang=HANGHOA.mahang", conn);
            SqlCommand cmd1 = new SqlCommand("insert into hoadon  values ('" + sohd + "','" + mahang + "'," + soluong.ToString() + "," + dongia.ToString() + "," + trigia.ToString() + "," + khuyenmai.ToString() + ",N'" + diengiai + "')", conn);
            cmd1.ExecuteNonQuery();
            conn.Close();
        }
      
    }
}
